require('module-alias/register')
var _ = require("lodash")
var { sunnyUser } = require('@Sequelize')


var token = function (req, res, next) {
    var {grantType} = _.assign({},req.body,req.query)
    if(grantType=='captcha'){
        return captchaLogin(req, res, next)
    }
    return captchaLogin(req, res, next)
}
function captchaLogin(req, res, next){
    var {username,tenantId} = _.assign({},req.body,req.query)
    var options={
        where:{username,tenantId}
    }
    return new Promise((resolve,reject)=>{
        sunnyUser.findOne(options).then((data)=>{

        res.json(data)
        }).catch((err)=>{
            next(err)
        })
    })
}
module.exports = { token };